#include <iostream>
#include <iomanip>
#include <limits>
#include "EquationSolver.h"

using namespace std;

double ftest(double x){
    return (x-1)*(x-1)*(x-1);
}

double dftest(double x){
    return 3*(x-1)*(x-1);
}

int main()
{
    typedef double (*fp)(double);
    fp fpi = ftest;
    fp dfpi = dftest;
    MyFunc f(fpi,dfpi);
    cout << "Question A: " << endl;
    cout << "f(x) = (x-1)^3 for test " << endl;
    double err = std::numeric_limits<double>::epsilon();    //应该是这里要limits

    Bisection B(-3,3,err,err,100,f);
    Newton N(3,err,100,f);
    Secant S(5,3,err,err,100,f);

    cout << "The bisection result is " << setiosflags(ios::fixed) << setprecision(2) << B.solve() << endl;
    cout << "The Newton result is " << setiosflags(ios::fixed) << setprecision(2) << N.solve() << endl;
    cout << "The secant result is " << setiosflags(ios::fixed) << setprecision(2) << S.solve() << endl;
    cout << endl;

    return 0;
}